package com.atguigu.gmall.weball.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.client.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@SuppressWarnings("all")
public class ItemController {
    @Autowired
    private ItemFeignClient itemFeignClient;

    @RequestMapping("{skuId}.html")
    public String getItem(@PathVariable Long skuId, Model model){
        //远程调用接口获取数据
        Result<Map> result = itemFeignClient.getItemBySkuId(skuId);
        //存储数据
        /*model.addAttribute("map",result.getData());
           按照这种方式需要遍历获取通过map导航,map导航指map.key来获取
           model.addAllAttributes(result.getData());
           而这种方式直接就可以获取里边的数据了
        */
        model.addAllAttributes(result.getData());
        return "item/item";
    }

}
